import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Solution {
    public int removeElement(int[] nums, int val) {

        /*if(nums == null || nums.length == 0){
            return 0;
        }
        int len = nums.length;
        Arrays.sort(nums);

        for (int j = 0; j < len-1; j++) {
            while(nums[j] == val && j<len-1){
                for (int i = j; i < len-1; i++) {
                    nums[i] = nums[i+1];
                }
                len--;
                if(nums[j] != val){
                    break;
                }
            }
        }
        if(nums[len-1] == val){
            len--;
        }
        return len;*/

        /*int left = 0;
        for (int right = 0; right < nums.length; right++) {
            if(nums[right] != val){
                nums[left] = nums[right];
                left++;
            }
        }
        return left;*/

        int left = 0;
        int right = nums.length;

        while(left < right){
            if(nums[left] == val){
                nums[left] = nums[right-1];
                right--;
            }else{
                left++;
            }
        }
        return left;
    }
    public int removeDuplicates(int[] nums) {

        /*if(nums == null || nums.length == 0){
            return 0;
        }
        int len = nums.length;

        for (int j = 0; j < len-1; j++) {
            while(j<len-1 && nums[j] == nums[j+1]){
                for (int i = j; i < len-1; i++) {
                    nums[i] = nums[i+1];
                }
                len--;
            }
        }

        return len;*/

        if(nums.length == 0 || nums == null){
            return 0;
        }

        int left = 1;

        for (int right = 1; right < nums.length; right++) {
            if(nums[right] != nums[right-1]){
                nums[left] = nums[right];
                left++;
            }
        }
        return left;
    }

    public static void main(String[] args) {
        /*int[] nums1 = {1, 2, 3, 0, 0, 0};
        int[] nums2 = {2, 5, 6};
        int m= 3;
        int n=3;
        merge(nums1, m, nums2, n);
        for (int x:
             nums1) {
            System.out.println(x);
        }*/
        printYangTriangle(9);

    }
    public static void merge(int[] nums1, int m, int[] nums2, int n) {
        int i = 0;
        int j = 0;

        while(j < n){
            while (nums1[i] < nums2[j] && i < m){
                i++;
            }
            if(i < m){
                for (int k = m-1; k >= i; k--) {
                    nums1[k+1] = nums1[k];
                }
            }
            nums1[i] = nums2[j];
            m++;
            j++;
        }
        /*int i=m;
        int j=0;

        while(i < m+n){
            nums1[i] = nums2[j];
            i++;
            j++;
        }
        Arrays.sort(nums1);*/
    }

    public static void printYangTriangle(int row){
        List<List<Integer>> listArrayList = new ArrayList<>();
        int n=1;

        List<Integer> list1 = new ArrayList<>();
        list1.add(1);
        listArrayList.add(list1);
        n++;

        if(row > 1){
            List<Integer> list2 = new ArrayList<>();
            list2.add(1);
            list2.add(1);
            listArrayList.add(list2);
            n++;
        }

        while(n <= row){
            List<Integer> list = new ArrayList<>();
            list.add(1);
            for (int i = 1; i < n-1; i++) {
                list.add(listArrayList.get(n-2).get(i-1) + listArrayList.get(n-2).get(i));
            }
            list.add(1);
            listArrayList.add(list);
            n++;
        }

        for (List<Integer> listRet:
             listArrayList) {
            System.out.println(listRet);
        }

    }
}
